package ru.paswd.marketprice.rest.api.dto;

import lombok.Getter;
import org.springframework.data.domain.Page;

import java.util.List;

@Getter
public class PageResponse<T> {
    private final int pageSize;
    private final int pageNumber;
    private final int totalPages;
    private final int totalOnPage;
    private final List<T> content;

    public PageResponse(List<T> content) {
        this.pageNumber = 0;
        this.pageSize = content.size();
        this.totalPages = 1;
        this.totalOnPage = content.size();
        this.content = content;
    }

    public PageResponse(Page<T> content) {
        this.pageNumber = content.getNumber();
        this.pageSize = content.getSize();
        this.totalPages = content.getTotalPages();
        this.totalOnPage = content.getContent().size();
        this.content = content.getContent();
    }
}
